import {getTypeName} from "./tab_mapping_fun";

//分页
let tabPage = {
  total: 0,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1,
  pageSizeOpts: [40, 60, 80, 120],
  tableLoading: false,
  noDataText: "暂无数据",
};
let mappingPage = {
  total: 0,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1,
  pageSizeOpts: [40, 60, 80, 120],
  tableLoading: false,
  noDataText: "正在查询...",
};

//弹窗
let status = {
  mappingModal: {
    isShow: false,
    title: "",
    okText: "保存",
    width: 900,
    height: 520,
    searchPlaceHolder: "输入产品名称或编号",
  },
};

//网络参数
let params = {
  tab: {
    id: "",
    name: "",
    type: 0,
  },
  isAddMappings: true,
  // selectedTabs: [],
  tabId: "",
  tabType: 0,
  selectedMappings: [],
  search: "",
  chosenCategory: {
    id: "",
    level: ""
  }
};

//页面数据源
let data = {
  tabList: [],
  tab: {id: "", name: "", type: 0, typeName: "", noSeo: false, description:"", createtime: ""},
  mappingList: [],
  product: {id: "", code: "", name: "", listImgUrl: "", currentPrice: 0, priceUnit: ""},
  user: {id: "", mobile: "", firstname: "", lastname: "", fullName: "", avatar: "", registertime: "", sex: ""},
  order: {id: "", userName: "", originalPrice: 0, actualPayment: 0, createtime: "", payWayName: ""},
  categoryList: [],
};

//标签表头
let tabTable = function (self) {
  return [
    // {type: 'selection', width: 55, align: 'center', fixed: 'left'},
    {title: "序号", type: 'index', width: 55, align: 'center',},
    {title: '标签名称', minWidth: 150, align: 'center', key: 'name'},
    {title: '标签类型', width: 200, align: 'center', render: (h, params) => {
      let typeName = getTypeName(params.row.type);
      return h("div", typeName);
    }},
    {title: '创建时间', width: 250, align: 'center', render: (h, params) => {
      return h("div", self.$tiyBJTime(params.row.createtime));
    }},
    {title: '综合操作', align: 'center', minWidth: 250, render: (h, params) => {
      return h("div", [
        h("Button", {
          props: {type: 'primary', size: 'small', icon: "md-add"},
          style: {marginRight: '8px'},
          on: {
            click: () => {
              self.showMappingsModal(params.row.type, true, params.row.id);
            }
          }
        }, "添加"+getTypeName(params.row.type)),
        h("Button", {
          props: {type: 'error', size: 'small', icon: "md-remove"},
          style: {marginRight: '8px'},
          on: {
            click: () => {
              self.showMappingsModal(params.row.type, false, params.row.id);
            }
          }
        }, "移除"+getTypeName(params.row.type))
      ]);
    }},
  ];
};

//产品表头
let productTable = function (self) {
  return [
    {type: 'selection', width: 55, align: 'center',},
    {title: "序号", type: 'index', width: 55, align: 'center',},
    {title: 'SKU', align: 'center', width: 160, key: 'code'},
    {title: "产品名", align: "left", key: "name", tooltip: true},
    {title: "状态", align: "center", width: 120, render(h, params) {
      let stateName = params.row.state==-1?"已下架":(params.row.state==0?"已上架":"已删除");
      return h("span", stateName);
    }},
    {title: "产品图片", align: "center", width: 100, render(h, params) {
      let yunPath = self.yunPath
      let imgUrl = params.row.productImg;
      if(imgUrl!=null && imgUrl!="") {
        return h("img", {
          attrs: {src: imgUrl},
          style: {display: "inline-block", maxHeight: "60px", maxWidth: "60px", verticalAlign: "middle", margin: "5px;"},
        });
      }
    }},
    // {title: "产品价格", align: "center", width: 100, key: "currentPrice"}
  ];
};

//用户表头
let userTable = function (self) {

};

//订单表头
let orderTable = function (self) {

};

//常量
let constData = {
  //标签类型
  tabType: {
    product: 1,
    user: 2,
    order: 3,
  }
}

export default  {
  tPage: {
    tabPage: tabPage,
    mappingPage: mappingPage
  },
  tStatus: status,
  tParam: params,
  tData: data,
  tTable: {
    tabTable: tabTable,
    productTable: productTable,
    userTable: userTable,
    orderTable: orderTable,
  },
  tConst: constData,
};
